#ifndef __MY_COMM_
#define __MY_COMM_
#include <unistd.h>
#include <string>
#include <iostream>
#include "json.hpp"

using namespace std;
class Request
{
public:
    int _x;
    int _y;
    string _op;
    int _result;
    int _code;

    Request(string str)
    {
        Json::Value root = unserialize(str);
        _x = root["x"].asInt();
        _y = root["y"].asInt();
        _op = root["op"].asString();
    }

    string handler()
    {
        if(_op == "+")
        {
            _result = _x + _y;
        }
        else if(_op == "-")
        {
            _result = _x - _y;
        }
        else if(_op == "*")
        {
            _result = _x * _y;
        }
        else
        {
            if(_y == 0)
                _result = -1;
        }

        char buffer[1024] = {0};
        snprintf(buffer, sizeof(buffer) - 1, "[%d]%s[%d]=[%d]", _x, _op.c_str(), _y, _result);
        string str(buffer);
        return str;
    }
};


#endif